/**
 * @author C.A. Burrell (deltafront@gmail.com)
 */

package gaboli.common.utils;

import java.util.Collection;
import java.util.Map;

/**
 * This class contains various convenience methods for seeing if various objects (Collections, Strings and the like)
 * are "empty".
 *
 * @author C. Burrell (deltafront@gmail.com)
 */
public class StringUtils
{
    /**
     * Tests to see if the map is null or empty
     *
     * @param map map to be evaluated.
     * @return true if map is null or empty.
     * @since 1.0
     */
    @SuppressWarnings( "unchecked" )
    public static boolean isEmpty( Map map )
    {
        return ( map == null || map.isEmpty() || map.size() == 0 );
    }

    /**
     * Tests to see if the collection is null or empty
     *
     * @param collection Collection to be evaluated.
     * @return true if collection is null or empty.
     * @since 1.0
     */
    @SuppressWarnings( "unchecked" )
    public static boolean isEmpty( Collection collection )
    {
        return ( collection == null || collection.isEmpty() || collection.size() == 0 );
    }

    /**
     * Tests to see if the string is null, a set of empty quotes, or of zero length
     *
     * @param string String to be evaluated.
     * @return true if the string is null, a set of empty quotes, or of zero length
     * @since 1.0
     */
    public static boolean isEmpty( String string )
    {
        return ( string == null || string.length() == 0 );
    }

    /**
     * Tests to see if the stringbuffer is null or of zero length
     *
     * @param string String to be evaluated.
     * @return true if the stringbuffer is null or of zero length .
     * @since 1.0
     */

    public static boolean isEmpty( StringBuffer string )
    {
        return ( string == null || string.length() == 0 );
    }

    /**
     * Determines whether this string is not-null and has a length greater than zero.
     *
     * @param string String to be evaluated.
     * @return True if this is a not-null / non-zero length string.
     * @since 1.0
     */
    public boolean isValidString( String string )
    {
        return ( string != null && string.length() > 0 );
    }

    /**
     * Determines if two Objects equal one another by using multiple methods.
     *
     * @param o1 First String to be compared.
     * @param o2 Second String to be compared.
     * @return true if s1 == s2 or s1.equals(s2) or s1.compareTo(s2) == 0.
     * @since 1.0
     */
    public boolean strictEquals( Object o1, Object o2 )
    {
        return  ( o1 == o2 ) ||
                ( o1.equals( o2 ) ) ||
                ( String.valueOf( o1 ).compareTo( String.valueOf( o2 ) ) == 0 );
    }

}
